<%@ page language="java" import="java.util.*,java.sql.*,java.util.Date,java.text.SimpleDateFormat"
	pageEncoding="utf-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@page import="com.bean.LoginBean"%>
<%
	int rowCount1=0;
	int rowCount2=0;
	LoginBean LoginBean = (LoginBean) session.getAttribute("Loginbean");
	String username = LoginBean.getUsername();
	Class.forName("com.mysql.jdbc.Driver").newInstance();
			String url = "jdbc:mysql://localhost:3306/graduatedesign";
			String user = "root";
			String password = "root";
			java.util.Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
			String date = dateFormat.format(now);
			Connection conn = (Connection) DriverManager.getConnection(url,
					user, password);
			Statement sm = (Statement) conn.createStatement();
			ResultSet rs = sm
					.executeQuery("select count(qiandao) from kaoqin where username='"+ username + "' and date='" + date+"'");
			if(rs.next()){
				rowCount1=rs.getInt(1);			
			}
			ResultSet rs2 = sm
					.executeQuery("select count(qiantui) from kaoqin where username='"+ username + "' and date='" + date+"'");
		
			if(rs2.next()){
				rowCount2=rs2.getInt(1);
			}
	
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>上下班打卡</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

</head>


<body>
	<table width="100%" border="0" cellpadding="0" cellspacing="1"
		bgcolor="#BBD3EB">
		<tr>
			<td height="26" align="center" bgcolor="#FFFFFF">
			<%
			if(rowCount1==0){ %>
                            	<a href="qiandao">签到</a>
                            	<%} %>
			</td>
			<td height="26" align="center" bgcolor="#FFFFFF">
			<%if(rowCount2==0){ %>
                            	<a href="qiantui">签退</a>
                            	<%} %>
			</td>
		</tr>
	</table>

	<br />


   <%
//定义四个分页会用到的变量
int pageSize=3;
int pageNow=1;//默认显示第一页
int rowCount=0;//该值从数据库中查询
int pageCount=0;//该值是通过pageSize和rowCount
//接受用户希望显示的页数（pageNow）
String s_pageNow=request.getParameter("pageNow");
if(s_pageNow!=null){
//接收到了pageNow
pageNow=Integer.parseInt(s_pageNow);
}
//查询得到rowCount

ResultSet rs3=sm.executeQuery("select count(*) from kaoqin where username='"+username+"'");
if(rs3.next()){
rowCount=rs3.getInt(1);
}
//计算pageCount
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//查询出需要显示的记录
rs3=sm.executeQuery("select date,qiandao,qiantui from kaoqin where username='"+username + "' limit " + (pageNow-1)*pageSize+","+pageSize);
%>

<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BBD3EB">
                          <tr>
                          <td height="27" align="center" background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">日期</td>
                            <td height="27" align="center" background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">签到时间</td>
                            <td height="27" align="center" background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">签退时间</td>
    </tr>
<%
while(rs3.next()){
%>
<tr>
                            <td height="26" align="center" bgcolor="#FFFFFF"><%=rs3.getDate(1)%></td>
                            <td height="26" align="center" bgcolor="#FFFFFF"><%=rs3.getString(2) %></td>
                            <td height="26" align="center" bgcolor="#FFFFFF"><%=rs3.getString(3)%></td>
                          </tr>
<%}%>

</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BBD3EB">

<%
//上一页
if(pageNow!=1){
out.println("<a href=admin/daka.jsp?pageNow="+(pageNow-1)+">上一页</a>");
}
//显示超链接
for(int i=1;i<=pageCount;i++){
out.println("<a href=admin/daka.jsp?pageNow="+i+">["+i+"]</a>");
}
//下一页
if(pageNow!=pageCount){
out.println("<a href=admin/daka.jsp?pageNow="+(pageNow+1)+">下一页</a>");
}
%>
</table>
</body>
</html>
